﻿unit SetENoteFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JvExControls, JvXPCore, JvXPButtons, ExtCtrls, FIBQuery,
  pFIBCacheQueries;

type
  TSetENoteForm = class(TForm)
    Panel1: TPanel;
    JvXPButton1: TJvXPButton;
    JvXPButton2: TJvXPButton;
    Note: TMemo;
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure JvXPButton1Click(Sender: TObject);
  private
    fEventCode: string;
    procedure SetEventCode(const Value: string);
  public
    property EventCode: string read fEventCode write SetEventCode;
  end;

var
  SetENoteForm: TSetENoteForm;

implementation
 uses  DModule;

{$R *.dfm}

{ TSetENoteForm }

procedure TSetENoteForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 case Key of
  VK_ESCAPE: ModalResult:=mrCancel;
  VK_TAB: ModalResult:=mrOk;
 end;
end;

procedure TSetENoteForm.JvXPButton1Click(Sender: TObject);
 var SQL: string;
     Q: TFIBQuery;
begin
 SQL:='UPDATE Events SET Note=:Note WHERE Code=:Code';
 dm1.trnWr.StartTransaction;
 Q:=GetQueryForUse(dm1.trnWr, SQL);
 Q.ParamByName('Note').AsString:=Note.Lines.Text;
 Q.ParamByName('Code').AsString:=EventCode;
 Q.ExecQuery;
 dm1.trnWr.Commit;
 FreeQueryForUse(Q);
end;

procedure TSetENoteForm.SetEventCode(const Value: string);
 var SQL: string;
     Q: TFIBQuery;
begin
 fEventCode := Value;
 SQL:='SELECT Note FROM Events WHERE Code=:Code';
 Q:=GetQueryForUse(dm1.trnRD, SQL);
 Q.ParamByName('Code').AsString:=fEventCode;
 Q.ExecQuery;
 Note.Lines.Text:=Q.FN('Note').AsString;
 FreeQueryForUse(Q);
end;

end.
